package pl.mchaniewski.ryneczek.web.admin;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;

import pl.mchaniewski.ryneczek.pojo.User;
import pl.mchaniewski.ryneczek.services.UserService;

@Component
@Scope("request")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public class UserListBean {
    private UserService userService;

    /* PostConstruct parameters */
    private List<User> userList;

    @Autowired
    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    public List<User> getUserList() {
        return userList;
    }

    @PostConstruct
    public void init() {
        userList = userService.findAll();
    }

}
